﻿Public Class CapNhatPhieuNhapKho_DAO

    'phần xử lý chi tiết phiếu nhập
    Public Shared Function SelectAll() As DataTable
        Dim strSQL As String = "select * from ChiTietPhieuNhap"
        Dim dt As DataTable
        dt = SQLProvider.ExecQuery(strSQL)
        Return dt
    End Function

    Public Shared Function SelectDSSPPNK() As DataTable
        Dim strSQL As String = "Select ChiTietPhieuNhap.MaSanPham, SP.TenSanPham, ChiTietPhieuNhap.SoLuong, ChiTietPhieuNhap.DonGia,ChiTietPhieuNhap.Makho from ChiTietPhieuNhap, SanPham SP where ChiTietPhieuNhap.MaSanPham=SP.MaSanPham "
        Dim dt As DataTable
        dt = SQLProvider.ExecQuery(strSQL)
        Return dt
    End Function

    Public Shared Function selectByMaPhieuNhapKho(_pnk As CapNhatPhieuNhapKho_DTO) As DataTable
        Dim dt As DataTable
        Dim strSQL As String = "select * from ChiTietPhieuNhap where SoPhieu like'%" & _pnk.SoPhieu & "%'"
        dt = SQLProvider.ExecQuery(strSQL)
        Return dt
    End Function

    Public Shared Sub Insert(_pnk As CapNhatPhieuNhapKho_DTO)
        Dim strSQL As String = "Insert into ChiTietPhieuNhap(SoPhieu,MaSanPham,SoLuong,DonGia,MaKho) values('" & _pnk.SoPhieu & "','" & _pnk.MaSanPham & "'," & _pnk.SoLuong & "," & _pnk.DonGia & ",'" & _pnk.MaKho & "' )"
        SQLProvider.ExecNoneQuery(strSQL)
    End Sub
    Public Shared Sub Delete(_pnk As CapNhatPhieuNhapKho_DTO)
        Dim strSQL As String = "delete from ChiTietPhieuNhap where SoPhieu ='" & _pnk.SoPhieu & "'"
        SQLProvider.ExecNoneQuery(strSQL)
    End Sub

    Public Shared Sub Update(_pnk As CapNhatPhieuNhapKho_DTO)
        Dim strSQL As String = "Update ChiTietPhieuNhap set SoPhieu='" & _pnk.SoPhieu & "', MaSanPham='" & _pnk.MaSanPham & "' ,SoLuong=" & _pnk.SoLuong & ",DonGia=" & _pnk.DonGia & ",MaKho='" & _pnk.MaKho & "' where id = " & _pnk.id
        SQLProvider.ExecNoneQuery(strSQL)
    End Sub

    'phần xử lý chi tiết phiếu nhập
    Public Shared Function SelectAllPN() As DataTable
        Dim strSQL As String = "select * from PhieuNhap"
        Dim dt As DataTable
        dt = SQLProvider.ExecQuery(strSQL)
        Return dt
    End Function

    Public Shared Sub InsertPN(_pnk As CapNhatPhieuNhapKho_DTO)
        Dim strSQL As String = "Insert into PhieuNhap(SoPhieu,MaNhaCungCap,NgayNhap) values('" & _pnk.SoPhieu & "','" & _pnk.MaNhaCungCap & "','" & _pnk.NgayNhap & "' )"
        SQLProvider.ExecNoneQuery(strSQL)
    End Sub

    Public Shared Sub DeletePN(_pnk As CapNhatPhieuNhapKho_DTO)
        Dim strSQL As String = "delete from PhieuNhap where SoPhieu ='" & _pnk.SoPhieu & "'"
        SQLProvider.ExecNoneQuery(strSQL)
    End Sub

    Public Shared Sub UpdatePN(_pnk As CapNhatPhieuNhapKho_DTO)
        Dim strSQL As String = "Update PhieuNhap set SoPhieu ='" & _pnk.SoPhieu & "' ,MaNhaCungCap ='" & _pnk.MaNhaCungCap & "' ,NgayNhap = '" & _pnk.NgayNhap & "', where SoPhieu = '" & _pnk.SoPhieu & "'"
        SQLProvider.ExecNoneQuery(strSQL)
    End Sub

    Public Shared Function SelectBySP(sp As String) As DataTable
        Dim strSQL As String = "select * from ChiTietPhieuNhap where SoPhieu = '" & sp & "'"
        Dim dt As DataTable
        dt = SQLProvider.ExecQuery(strSQL)
        Return dt
    End Function

    Public Shared Function SelectBySP1(sp As String) As DataTable
        Dim strSQL As String = "select MaSanPham,SoLuong,DonGia,MaKho from ChiTietPhieuNhap where SoPhieu = '" & sp & "'"
        Dim dt As DataTable
        dt = SQLProvider.ExecQuery(strSQL)
        Return dt
    End Function

End Class
